package com.freexiaoyu.freevideoplay;

import android.net.Uri;
import android.net.http.UploadDataProvider;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;

import androidx.annotation.OptIn;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatEditText;


import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.ui.PlayerView;

import java.io.File;
import java.io.IOException;

public class ExoPlayerActivity extends AppCompatActivity {



    PlayerView mPlayerView;
    private ExoPlayer mExoPlayer;


    AppCompatEditText etUrl;
    AppCompatButton btnPlay;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_exoplayer);

        mPlayerView = findViewById(R.id.player_view);
        etUrl = findViewById(R.id.et_url);
        btnPlay = findViewById(R.id.btn_play);

        //String videoPath= Environment.getExternalStorageDirectory() + File.separator + "Documents" + File.separator+"1735606270841.mp4";
        String videoPath = Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "Screenshots" + File.separator + "SVID_20241230_110118_1.mp4";


        btnPlay.setOnClickListener(v -> play(etUrl.getText().toString().trim()));
    }

    private void play(String url) {


        mExoPlayer = new ExoPlayer.Builder(getBaseContext()).build();
        mPlayerView.setPlayer(mExoPlayer);
        mExoPlayer.setMediaItem(MediaItem.fromUri(url));
        mExoPlayer.prepare();
        mExoPlayer.play();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}